package com.suning.sawp.web.controller;

import java.security.Principal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.constants.LoggerConstants;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.logistics.LogisticsOrderList;
import com.suning.sawp.intf.logistics.OrderInfoService;
import com.suning.sawp.web.exception.MyGsonView;

/**
 * 
 * 订单查询controller<br>
 * 〈功能详细描述〉
 * 
 * @author Wuxiao
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/order")
public class OrderInfoController extends DjBaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstants.SAWP_SERVICE);

    @Autowired
    OrderInfoService  orderInfoService;

    /**
     * 
     * 功能描述: 查询订单列表<br>
     * 〈功能详细描述〉
     *
     * @param storeCode 门店代码
     * @param telNo 手机号
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param start 起始值
     * @param limit 每页大小
     * @param principal
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    @RequestMapping("/queryOrder.do")
    public MyGsonView queryOrder(String storeCode,String telNo,String startTime,String endTime,Integer start,Integer limit,Principal principal){
        MyGsonView gsonView = createGsonView();
        ReturnMsg<LogisticsOrderList> ret = new ReturnMsg<LogisticsOrderList>();
        try {
            ret = orderInfoService.queryOrderListByPage(storeCode, principal.getName(), telNo, startTime, endTime, start, limit);
        } catch (Exception e) {
            ret.setRetFlag(ReturnMsg.FAIL);
            ret.setErrorCode(ErrorCodeConstants.QUERY_ORDER_ERR_E999);
            ret.setErrorMessage(ErrorCodeConstants.QUERY_ORDER_ERR_MAP
                    .get(ErrorCodeConstants.QUERY_ORDER_ERR_E999));
            LOGGER.error("物流信息查询订单列表异常",e);
        }
        gsonView.addStaticAttribute("ret", ret);
        gsonView.setJsonObjectName("ret");
        return gsonView;
    }
}
